package com.ptrsystem.siatd.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.ptrsystem.siatd.dao.logica.MantenimientoUbigeoLogica;
import org.springframework.beans.factory.annotation.Autowired;
import com.ptrsystem.siatd.beans.Ubigeo;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.*;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class UbigeoController {

    @Autowired
    private MantenimientoUbigeoLogica logica;

    @RequestMapping(value = "registrarUbigeo.htm", method = RequestMethod.GET)
    private String resgistrarUbigeo() {
        return "Mantenimiento/NRegUbigeo";
    }

    @RequestMapping(value = "registraUbigeo.htm", method = RequestMethod.POST)
    private String registraUbigeo(Ubigeo ubi, HttpServletRequest req) {

        boolean rs = logica.registraUbigeo(ubi);
        if (rs) {
            req.getSession(false).setAttribute("result", "registro Satidfactorio");
        } else {
            req.getSession(false).setAttribute("result", "Error Al Registrar");
        }
        return "Mantenimiento/NRegUbigeo";
    }

    @RequestMapping(value = "listarubigeos.htm")
//    private void listaUbigeos(@RequestParam("dep") String dep, @RequestParam("pro") String pro,
//            @RequestParam("dis") String dis, @RequestParam("otr") String otr, HttpServletRequest req, HttpServletResponse res) throws IOException {
    private void listaUbigeos(HttpServletRequest req, HttpServletResponse res) throws IOException {
        PrintWriter out = res.getWriter();
        List<Ubigeo> lista = logica.getListaUbigeo("", "", "", "");
        out.print(lista.get(1).getNomDist());
        out.close();

    }

}
